package plugins.jTreeFolder;

import java.awt.Component;
import java.io.Serializable;

import javax.swing.Icon;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;

public class Renderer extends DefaultTreeCellRenderer implements Serializable {
    
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public Renderer() {
        super();
    }
    
    public Component getTreeCellRendererComponent(JTree tree,Object value,boolean selected, 
                                                boolean expanded,boolean leaf,int row, 
                                                boolean hasFocus) {
        
                                                  
        try {
            NodeWithFile node = (NodeWithFile) value;
            Icon icone = javax.swing.filechooser.FileSystemView.getFileSystemView().getSystemIcon(node.getFile());
            
            if(expanded) {
                setOpenIcon(icone);  
            } 
            if(leaf) {
                setLeafIcon(icone);
            } 
            if(!expanded && !leaf) {
                setClosedIcon(icone);
            }
            
        }
        catch (Exception ex) {
            
        }
        super.getTreeCellRendererComponent(tree, 
                                        value, 
                                        selected, 
                                        expanded, 
                                        leaf, 
                                        row, 
                                        hasFocus);
        return this;
    }
}